package chapter05;

public class Test05_throw {
    public static void main(String[] args) throws Exception{
        setAge(10);
        setAge(-10);
    }
    static void setAge(int age) throws Exception{
        if(age<0){
            //直接手动抛出异常
            throw new Exception("年龄不能为负数");
        }else{
            System.out.println("年龄为："+age);
        }
    }
}
